home *** CD-ROM | disk | FTP | other *** search
/ Freaks Macintosh Archive / Freaks Macintosh Archive.bin / Freaks Macintosh Archives / Textfiles / zines / Phrack / Phrack Issue 51.sit / Phrack51 / P51-13 < prev    next >
Text File  |  1997-09-01  |  15KB  |  480 lines

  1. ---[  Phrack Magazine   Volume 7, Issue 51 September 01, 1997, article 13 of 17
  2.  
  3.  
  4. -------------------------[  Monoalphabetic Cryptanalysis (Cyphers, Part One)
  5.  
  6.  
  7. --------[  Jeff Thompson aka 'Mythrandir' <jwthomp@cu-online.com>
  8.  
  9.  
  10.  
  11. Written for Phrack and completed on Sunday, August 31st, 1997.
  12.  
  13.  
  14. ---------
  15.  
  16. First a quick hello to all of those I met at DefCon this year.  It was 
  17. incredible fun to finally put faces to many of the people I have been talking 
  18. with for some time.  It was truly was a treat to meet so many others who are 
  19. alive with the spirit of discovery.  
  20.  
  21. ----------
  22.  
  23.  
  24. This is the first in a series of articles on Cryptology that I am writing.  
  25. The goals of these articles will be to attempt to convey some of the excitement
  26. and fun of cyphers.  A topic of much discussion in regards to cryptography 
  27. currently, is about computer based cyphers such as DES, RSA, and the PGP 
  28. implementation.  I will not be discussing these.  Rather, these articles will 
  29. cover what I will term classical cryptology.  Or cryptology as it existed 
  30. before fast number crunching machines came into existance.  These are the sorts
  31. of cyphers which interested cryptographers throughout time and continue to be 
  32. found even to this very day.  Even today, companies are producing software 
  33. whose encryption methods are attackable.  You will find these commonly among 
  34. password protection schemes for software programs.  Through the course of these
  35. articles I will explain in practical terms several common cypher types and 
  36. various implementations of them as well as cryptanalytic techniques for 
  37. breaking these cyphers.
  38.  
  39. Creating cyphers is fun and all, but the real excitement and often times tedium
  40. is found in Cryptanalysis.  Many of the ideas presented in these articles will 
  41. based on three sources.  The following two books: The Codebreakers by David 
  42. Kahn (ISBN: 0-684-83130-9) and Decrypted Secrets by F.L. Bauer 
  43. (ISBN: 3-540-60418-9).  Both authors have put together wonderful books which 
  44. both cover the history and methods of Cryptology.  Do yourself and the authors 
  45. a favor and purchase these books.  You will be very pleased with the lot.  
  46. Finally, a miniscule amount of these articles will be written based on my own 
  47. personal experience.  
  48.  
  49. The fun is in the journey and I welcome you on what is certain to be an 
  50. interesting trip.  Please feel free to raise questions, engage me in 
  51. discussions, correct me, or simply offer suggestions at jwthomp@cu-online.com.
  52. Please be patient with me as I am traveling extensively currently, and may be 
  53. away from the computer at length occasionally.  
  54.  
  55. Out the door and into the wild...
  56.  
  57.  
  58. --Monoalphabetic Cyphers
  59.  
  60. Monoalphabetic cyphers are often currently found in simple cryptograms in books
  61. and magazines.  These are just simple substitution cyphers.  This does not 
  62. mean that they are always simple for the beginning amateur to solve.
  63.  
  64. Three common monoalphabetic cyphers which are used are substitution, cyclical, 
  65. and keyed cyphers.
  66.  
  67.  
  68. -Substitution Cyphers 
  69.  
  70. By taking an alphabet and replacing each letter with another letter in a 
  71. unique fashion you create a simple monoalphabetic cypher.  
  72.  
  73. Plaintext Alphabet    A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
  74. Cypher Alphabet        Z I K M O Q S U W Y A C E B D F H J L N P R T V X G
  75.  
  76.  
  77. Plaintext Message
  78.  
  79. The blue cow will rise during the second moon from the west field.
  80.  
  81. Cyphertext Message
  82.  
  83. nuo icpo kdt twcc jwlo mpjwbs nuo lokdbm eddb qjde nuo toln qwocm.
  84.  
  85.  
  86. -Cyclical Cyphers
  87.  
  88. By taking an alphabet and aligning it with a rotated alphabet you get a 
  89. cyclical cypher.  For example:
  90.  
  91. Plaintext Alphabet    A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
  92. Cypher Alphabet        N O P Q R S T U V W X Y Z A B C D E F G H I J K L M
  93.  
  94.  
  95. Indeed, you may recognize this cypher as a ROT13 which is commonly used on 
  96. news groups to obscure messages.
  97.  
  98.  
  99. -Keyed Cypher
  100.  
  101. Another way to create a monoalphabetic cypher is to choose a keyword or phrase 
  102. as the beginning of the cypher alphabet. Usually, only the unique letters from 
  103. the phrase are used in order to make sure the plaintext to cyphertext behaves 
  104. in a one to one fashion.
  105.  
  106. For example:
  107.  
  108. Plaintext Alphabet:    A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
  109. Cypher Alphabet        L E T O S H D G F W A R B C I J K M N P Q U V X Y Z
  110.  
  111. The passphrase in this cypher is "Let loose the dogs of war"  The advantage of 
  112. such a system is that the encryption method is easy to remember.  Also, a 
  113. method of key change can be created without ever having to distribute the keys.
  114. For example, one could use the 4 words at a time of some piece of literature.  
  115. Every message could use the next four words.  Indeed, this change could occur 
  116. more frequently, but that is a subject for another article. 
  117.  
  118.  
  119. -Bipartite Substitution
  120.  
  121. Bipartite substition is the use of symbol pairs to represent plaintext.  Later 
  122. we will see that this sort of substitution lends itself to be easily made more 
  123. difficult to analyze. Two examples of this are:
  124.  
  125.   1 2 3 4 5                                     A B C D E
  126. 1 A B C D E                             A A B C D E 
  127. 2 F G H I J                             B F G H I J
  128. 3 K L M N O                             C K L M N O
  129. 4 P Q R S T                or             D P Q R S T
  130. 5 U V W X Y                             E U V W X Y
  131. 6 Z 0 1 2 3                             F Z 0 1 2 3
  132. 7 4 5 6 7 8                             G 4 5 6 7 8
  133. 9 9 . - ? ,                             H 9 . - ? ,
  134.  
  135.  
  136. Obviously, the letters do not need to be placed in this order as their solutions 
  137. would not be that difficult to guess.
  138.  
  139.  
  140.  
  141. --Cryptanalysis
  142.  
  143.  
  144. Previously we created a cyphered message:
  145.  
  146. nuo icpo kdt twcc jwlo mpjwbs nuo lokdbm eddb qjde nuo toln qwocm.
  147.  
  148.  
  149. If one were to receive this message, figuring out its contents might seem 
  150. fairly daunting. However,  there are some very good methods for recovering the 
  151. plaintext from the cyphertext. The following discussion will work under the 
  152. assumption that we know the cyphers with which we are dealing are 
  153. monoalphabetics.
  154.  
  155.  
  156. -Frequency Analysis
  157.  
  158. The first method we will use is frequency analysis.  Natural languages have 
  159. many qualities which are very useful for the analysis of cyphertext.  Languages
  160. have letters which occur more commonly in text, collections of letters which 
  161. are more frequent,  patterns in words, and other related letter occurances.  
  162.  
  163. Counting up the occurances of letters we find that there are...
  164.  
  165. letter    occurances
  166. b        3
  167. c        4
  168. d        5
  169. e        2
  170. i        1
  171. j        3
  172. k        2
  173. l        3
  174. m        3
  175. n        4
  176. o        8
  177. p        2
  178. q        2
  179. s        1
  180. t        3
  181. u        3
  182. w        4
  183.  
  184. The order of greatest frequency to least is:
  185.  
  186.  8   5     4          3           2       1
  187. {o} {d} {c n w} {b j l m t u} {e k p q} {i s} 
  188.  
  189.  
  190. If this sort of analysis were run on many volumes of english you would find that
  191. a pattern would emerge.  It would look like this:
  192.  
  193. {e} {t} {a o i n} {s r h} {l d} {c u m f} {p g w y b} {v k} {x j q z}
  194.  
  195. You will notice an immediate correlation between e and o.  However, for the 
  196. rest of the letters we can not be very certain.  In fact, we can not be very 
  197. certain about e either.
  198.  
  199. Since this text is short it is helpful to take a look at some of the other 
  200. behaviors of this text.
  201.  
  202. Counting up the first, second, third, and last letters of the words in this 
  203. text we find the following frequencies:
  204.  
  205.  
  206. First Letter in word        Occurances
  207.  
  208. e                    1
  209. i                    1
  210. j                    1
  211. k                    1
  212. l                    1
  213. m                    1
  214. n                    3
  215. q                    2
  216. t                    2
  217.  
  218. Order:
  219.  
  220. n q t e i j k l m
  221.  
  222.  
  223. Second letter in word        Occurances
  224. c                    1
  225. d                    2
  226. i                    1
  227. n                    1
  228. o                    2
  229. p                    1
  230. u                    3
  231. w                    3
  232.  
  233. Order:
  234.  
  235. u w d o c i n p
  236.  
  237.  
  238. Third letter in word        Occurances
  239.  
  240. c                    1
  241. d                    2
  242. i                    1
  243. k                    1
  244. l                    2
  245. o                    4
  246. p                    1
  247. t                    1
  248. u                    1
  249.  
  250. Order:
  251.  
  252. o d l c i k p t u
  253.  
  254.  
  255. Last letter in word        Occurances
  256.  
  257. b                    1
  258. c                    1
  259. e                    1
  260. m                    1
  261. n                    1
  262. o                    5
  263. s                    1
  264. t                    1
  265.  
  266.  
  267. English frequency for first letter:
  268.  
  269. t a o m h w 
  270.  
  271. Second letter:
  272.  
  273. h o e i a u 
  274.  
  275. Third letter:
  276.  
  277. e s a r n i
  278.  
  279. Last letter:
  280.  
  281. e t s d n r 
  282.  
  283. Noticing the higher frequency count for 'o' in the third and last letters of 
  284. words in addition to its absence as a first letter in any words gives us strong
  285. reason to believe that 'o' substitutes for 'e'.  This is the first wedge into 
  286. solving this cypher.
  287.  
  288. However, do not be fooled by the apparent strengths of frequency analysis.  
  289. Entire books have been written without the use of some letters in the English 
  290. alphabet.  For instance The Great Gatsby was written without using the letter 
  291. 'e' in one word of the book.
  292.  
  293.  
  294. Other items to analyze in cyphertext documents is the appearance of letters in 
  295. groups.  These are called bigrams and trigrams.  For example, 'th' is a very 
  296. common letter pairing in the english language.  Also, as no surprise 'the' is 
  297. a very common trigram.  Analysis of english documents will find these results 
  298. for you.
  299.  
  300.  
  301. So now that that we have developed a simple way of starting to attack cyphers 
  302. lets examine a few ways to make them more difficult to break.
  303.  
  304.  
  305. --Strengthening Cyphers
  306.  
  307.  
  308. -Removing word and sentence boundaries
  309.  
  310. A simple way to complicate decypherment of a cyphertext is to remove all 
  311. spacing and punctuation.  This makes it more difficult to perform a frequency 
  312. analysis on letter positions.  However, it is possible to make reasonable 
  313. guesses as to word positions once yoy begin to study the document.  Another 
  314. method is to break the cyphertext into fixed blocks.  For example after every 
  315. four letters a space is placed.
  316.  
  317. The previous cypher text would appear as this:
  318.  
  319. nuoicpokdttwccjwlompjwbsnuolokdbmeddbqjdenuotolnqwocm.
  320.  
  321.  
  322. or this:
  323.  
  324. nuoi cpok dttw ccjw lomp jwbs nuol okdb medd bqjd enuo toln qwoc m
  325.  
  326.  
  327. You will notice that the above line ends with a single character.  This gives 
  328. away the end of the text and would be better served by the placement of nulls, 
  329. or garbage characters.  The above line becomes:
  330.  
  331. nuoi cpok dttw ccjw lomp jwbs nuol okdb medd bqjd enuo toln qwoc mhew
  332.  
  333. 'hew' will decypher to 'qmi' which will clearly appear to be nulls to the 
  334. intended recipient.
  335.  
  336.  
  337. -Nulls
  338.  
  339. Nulls are characters used in messages which have no meanings.  A message could 
  340. be sent which uses numbers as nulls. This makes decypherment more difficult as
  341. part of the message has no meaning.  Until the decypherer realizes this, he 
  342. may have a hard time of solving the message.
  343.  
  344.  
  345. -Polyphony
  346.  
  347. Another method that can be applied is the use of polyphones.  Polyphones are 
  348. simply using a piece of cyphertext to represent more than one piece of 
  349. plaintext.  For example a cyphertext 'e' may represent an 'a' and a 'r'.  This 
  350. does complicate decypherment and may result in multiple messages.  This is 
  351. dangerous as these messages are prone to errors and may even decypher into 
  352. multiple texts.
  353.  
  354. A new cyphertext alphabet would be
  355.  
  356. Cyphertext alphabet    A B C D E F G H I J L N P
  357. Plaintext alphabet    Z X U S Q O M K H N R V W
  358.             B D F G I A C E L P J T Y
  359.  
  360. Our old plaintext message becomes
  361.  
  362. nih aich gfp peii ledh bclejd nih dhgfjb gffj clfg nih phdn cehib
  363.  
  364. This decypherment becomes very tricky for someone to accomplish.  Having some 
  365. knowledge of the text would be a great help.
  366.  
  367. If it appears that very few letters are being used in a document then you may 
  368. wish to suspect the use of polyphones within a document.
  369.  
  370.  
  371. -Homophones
  372.  
  373. Homophones are similar to polyphones except that there is more than one 
  374. cyphertext letter for every plaintext letter.  They are useful to use in that 
  375. they can reduce the frequencies of letters in a message so that an analysis 
  376. yields little information.  This is very easy to do with bipartite 
  377. substitution cyphers.  For example:
  378.  
  379.          a b c d e
  380.        a a b c d e
  381.        b f g h i j
  382.        c k l m n o
  383.        d p q r s t
  384.        e u v w x y
  385.        f z * * * *
  386.  
  387. *(fb, fc, fd, fe are NULLS)
  388.  
  389. We can add homophones to the message like this:
  390.  
  391.           a b c d e
  392.  
  393.  i h g a  a b c d e
  394.    k j b  f g h i j
  395.    n l c  k l m n o
  396.    o m d  p q r s t
  397.      p e  u v w x y
  398.        f  z * * * *
  399.  
  400. The optimal way to set up these homophones is to calculate the frequency of 
  401. appearance in the natural language you are using of each row of letters.  
  402. Homophones should be added so that the cyphertext appearance of each homophone 
  403. is reduced to a level where frequency analysis would yield little information.
  404.  
  405.  
  406. -Code Words
  407.  
  408. One final method which can be used is that of code words.  Simply replace 
  409. important words in the plaintext with code words which represent another word.
  410. For example the nonsense plaintext that has been chosen for this document could 
  411. actually mean:
  412.  
  413.  
  414. The blue cow will rise during the second moon from the west field.
  415.  
  416. The king is angry and will attack in two weeks with the 1st calvary by way of 
  417. the foothills.
  418.  
  419. blue is angry
  420. cow is king
  421. rise is attack
  422. second is two weeks
  423. moon is 1st calvary
  424. west field stands for some foothills on the west side of the kingdom.
  425.  
  426.  
  427. Throughout this document I have mentioned frequency analysis of english 
  428. documents.  This is a fairly tedious task to do by hand, and so I am 
  429. developing software to aid in frequency analysis of documents.  I will be 
  430. making it available via my website at http://www.cu-online.com/~jwthomp/ on 
  431. Monday, September 8th.  Please watch for it in the Cryptography section.
  432.  
  433.  
  434. Ok, now to try your hand at a few cyphertexts..
  435.  
  436. This one has to do with war.
  437. 1)
  438. kau noelb'd oerf xmtt okkopw ok qoxb euoqf kau kurhtoe wbmcakds, obq dkemwu amd
  439. podktu xamtu xu altq amr   
  440.  
  441.  
  442. This one is an excerpt from a technical document.
  443. 2)
  444. etdsalwqs kpjsjljdq gwur orrh frurdjkrf sj qtkkjps npjtk ljeethalwsajhq   
  445. sgrqr kpjsjljdq tqr w jhr sj ewhy kwpwfane ijp spwhqeaqqajh sykalwddy tqahn 
  446. ldwqq f ahsrphrs kpjsjljd wffprqqrq sj qkrlaiy qkrlaial etdsalwqs npjtkq
  447.  
  448.  
  449. Mail me your answers and I'll put the first person who solves each cypher in 
  450. the next Phrack.
  451.  
  452. In fact, I would enjoy seeing some participation in this for the next Phrack.  
  453. After reading this, I welcome the submission of any "Monoalphabetic" cypher 
  454. based on the discussions of this article.  Please do not yet submit any 
  455. polyalphabetic cyphers (Next article).  When submitting to me, please send me 
  456. two letters.  The first mail should include only the encyphered text.  Make 
  457. sure it is enough so that a reasonable examination can be made of the cypher.
  458. This first mail should have a subject "Cyphertext submission".  If you are 
  459. using a method of encypherment not found in this article, please enclose a 
  460. brief description of the type of method you used.  Follow this mail up with 
  461. another entitled "Cyphertext Solution" along with a description of the 
  462. encyphering method as well as the key or table used.
  463.  
  464. I will select a number of these texts to be printed in the next Phrack, where
  465. readers may have a chance at solving the cyphers.  The reason I ask for two
  466. seperate mailing is that I will want to take a crack at these myself.  Finally,
  467. the names of individuals will be placed in the following phrack of the first
  468. to solve each cypher, and whomever solves the most cyphers prior to the next
  469. Phrack release (real name or pseudonym is fine).
  470.  
  471.  
  472. Please mail all submissions to jwthomp@cu-online.com
  473.  
  474. I welcome any comments, suggestions, questions, or whatever at 
  475. jwthomp@cu-online.com
  476.  
  477.  
  478. ----[  EOF
  479.  
  480.